package com.sc.webview;

import com.sc.app.R;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.Button;
import android.widget.TextView;

public class LoadWebView extends Activity implements OnClickListener , OnScrollListener{
	
	private WebView webView;
	private Button backBtn;
	private TextView top_title;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_PROGRESS);
		setContentView(R.layout.webview_i);
		backBtn = (Button) findViewById(R.id.btn_back);
		backBtn.setOnClickListener(this);
		initData();
	}
	
	@SuppressLint("SetJavaScriptEnabled") private void initData(){
		webView = (WebView) findViewById(R.id.webview_two);
		webView.loadUrl("http://www.baidu.com");
		webView.requestFocus();
		webView.setWebViewClient(new WebviewClient());
		webView.getSettings().setJavaScriptEnabled(true);
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if(( keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()){
			webView.goBack();
			return true;
		}
		return false;
	}
	
	/**
	 * 
	 * @author ASUS
	 *
	 */
	private class WebviewClient extends WebViewClient {
			@Override 
	        public boolean shouldOverrideUrlLoading(WebView view, String url) {  
	            view.loadUrl(url);  
	            return true;  
	        }  
	}
	@Override
	public void onClick(View view) {
		// TODO Auto-generated method stub
		switch (view.getId()) {
		case R.id.btn_back:
			goBack();
			break;
		}
	}
	private void goBack() {
		// TODO Auto-generated method stub
		LoadWebView.this.finish();
	}

	@Override
	public void onScroll(AbsListView arg0, int arg1, int arg2, int arg3) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onScrollStateChanged(AbsListView arg0, int arg1) {
		// TODO Auto-generated method stub
		
	}
}
